package com.risetek.tft.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.risetek.tft.service.impl.JsonDateSerializer;

/**
 * TManager entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "t_sys_manager", uniqueConstraints = @UniqueConstraint(columnNames = "account"))
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class TManager implements java.io.Serializable {

	// Fields

	private Integer managerid;
	private TRole TRole;
	private String account;
	private String password;
	private String name;
	private Boolean state;
	private Integer logintimes;
	private String lastloginip;
	private Timestamp lastlogintime;
    private String photo;
	// Constructors

	/** default constructor */
	public TManager() {
	}

	/** minimal constructor */
	public TManager(String account, String password, Boolean state) {
		this.account = account;
		this.password = password;
		this.state = state;
	}

	/** full constructor */
	public TManager(TRole TRole, String account, String password, String name,
			Boolean state ) {
		this.TRole = TRole;
		this.account = account;
		this.password = password;
		this.name = name;
		this.state = state;
	}

	// Property accessors
	@Id
	@Column(name = "managerid", unique = true, nullable = false, precision = 20, scale = 0)
	@GeneratedValue(strategy = IDENTITY)
	/*@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ACTIVITY_GENERATOR")
	@SequenceGenerator(name = "ACTIVITY_GENERATOR", sequenceName = "HIBERNATE_SEQUENCE")*/
	public Integer getManagerid() {
		return this.managerid;
	}

	public void setManagerid(Integer managerid) {
		this.managerid = managerid;
	}

	@ManyToOne(fetch = FetchType.LAZY )
	@JoinColumn(name = "role")
	public TRole getTRole() {
		return this.TRole;
	}

	public void setTRole(TRole TRole) {
		this.TRole = TRole;
	}

	@Column(name = "account", unique = true, nullable = false, length = 50)
	public String getAccount() {
		return this.account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	@Column(name = "password", nullable = false, length = 50)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "name", length = 50)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "state", nullable = false)
	public Boolean getState() {
		return this.state;
	}

	public void setState(Boolean state) {
		this.state = state;
	}
	
	@Column(name = "logintimes")
	public Integer getLogintimes() {
		return logintimes;
	}

	public void setLogintimes(Integer logintimes) {
		this.logintimes = logintimes;
	}

	@Column(name = "lastloginip", length = 15)
	public String getLastloginip() {
		return this.lastloginip;
	}

	public void setLastloginip(String lastloginip) {
		this.lastloginip = lastloginip;
	}

	@Column(name = "lastlogintime", length = 19)
	@JsonSerialize(using=JsonDateSerializer.class)
	public Timestamp getLastlogintime() {
		return this.lastlogintime;
	}

	public void setLastlogintime(Timestamp lastlogintime) {
		this.lastlogintime = lastlogintime;
	}
	
	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	@Transient
	public boolean getIssuper() {
		return this.managerid == 1;
	}

}